﻿
using Xacml.Core;
using System.Xml;

namespace Xacml.Core.Context
{
  public class StatusElement : XacmlElement
  {
    private StatusCodeElement _statusCode;
    private string _statusMessage;
    private string _statusDetail;

    public string StatusMessage
    {
      get
      {
        return this._statusMessage;
      }
    }

    public string StatusDetail
    {
      get
      {
        return this._statusDetail;
      }
    }

    public StatusCodeElement StatusCode
    {
      get
      {
        return this._statusCode;
      }
      set
      {
        this._statusCode = value;
      }
    }

    public override bool IsReadOnly
    {
      get
      {
        return true;
      }
    }

    public StatusElement(StatusCodeElement statusCode, string statusMessage, string statusDetail, XacmlVersion schemaVersion)
      : base(XacmlSchema.Context, schemaVersion)
    {
      this._statusCode = statusCode;
      this._statusMessage = statusMessage;
      this._statusDetail = statusDetail;
    }

    public StatusElement(XmlReader reader, XacmlVersion schemaVersion)
      : base(XacmlSchema.Context, schemaVersion)
    {
      if (!(reader.LocalName == "Status"))
        return;
      while (reader.Read())
      {
        switch (reader.LocalName)
        {
          case "StatusCode":
            this._statusCode = new StatusCodeElement(reader, schemaVersion);
            break;
          case "StatusMessage":
            this._statusMessage = reader.ReadElementString();
            break;
          case "StatusDetail":
            this._statusDetail = reader.ReadElementString();
            break;
        }
        if (reader.LocalName == "Status" && reader.NodeType == XmlNodeType.EndElement)
          break;
      }
    }
  }
}
